package com.digitalxpert.jargle.TestGui;

import java.awt.Component;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTabbedPane;
import javax.swing.text.JTextComponent;

public class TabbedPopupMenu extends JPopupMenu {
	private Action closeA;
	private JMenuItem closeItem;
	private JTabbedPane pane;
	public TabbedPopupMenu(){
		closeA = new CloseTabAction();
		closeItem = new JMenuItem(closeA);
		this.add(closeItem);
	}
	public void show(Component invoker, int x, int y){
		super.show(invoker, x, y);
		pane = (JTabbedPane)invoker;
	}
	public class CloseTabAction extends AbstractAction{
        public CloseTabAction(){
            super("Close");
            putValue(SHORT_DESCRIPTION, "Close2");
        }
        public void actionPerformed(ActionEvent e){
            int i = pane.getSelectedIndex();
            int count = pane.getComponentCount();
            /*if(count!=i+1){
            	((TabbedPane)pane).myFireStateChanged();
            }*/
            pane.remove(pane.getSelectedComponent());
        }
    }
}
